package org.example.spring.simple.framework.aop.intercept;

import org.example.spring.simple.framework.aop.aspect.ZAbstractAspectJAdvice;
import org.example.spring.simple.framework.aop.aspect.ZAdvice;
import org.example.spring.simple.framework.aop.aspect.ZJoinPoint;

import java.lang.reflect.Method;

/**
 * 前置通知的具体实现
 */
public class ZBeforeAdviceInterceptor extends ZAbstractAspectJAdvice implements ZMethodInterceptor, ZAdvice {
    private ZJoinPoint joinPoint;

    public ZBeforeAdviceInterceptor(Method method, Object target) {
        super(method, target);
    }

    private void before(Method method, Object[] args, Object target) throws Throwable {
        super.invokeAdviceMethod(this.joinPoint, null, null);
    }

    @Override
    public Object invoke(ZMethodInvocation invocation) throws Throwable {
        //从被织入的代码中才能拿到，JoinPoint
        this.joinPoint = invocation;
        before(invocation.getMethod(), invocation.getArguments(), invocation.getThis());
        return invocation.proceed();
    }
}
